package com.neuedu.io;

import java.io.*;

public class BufferedCharIO {


    /**
     * 带缓冲区的  字符读、写
     *
     * @param args
     */
    public static void main(String[] args) throws IOException {

        File readFile = new File("D:\\upload\\西游记.txt");
        File writeFile = new File("D:\\upload\\西游记备份.txt");
        Reader reader = new FileReader(readFile);
        Writer writer = new FileWriter(writeFile);
        ;


       //1.7+支持 try with
        try( BufferedReader br = new BufferedReader(reader);
             BufferedWriter bw = new BufferedWriter(writer,1000) ;
          ){   //会自动关闭 对象
            boolean ready = br.ready();
            System.out.println("ready = " + ready);
            if (ready) {
                String line = null;
                while (   (line = br.readLine()) != null  ){  //忽略了 \r\n
                    System.out.println(line);
                    bw.write(line+"\r\n");
                }

            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }


}
